<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("../Includes/FusionCharts.php");
include("../Includes/DBConn.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>UPLB DV</title>
<script language="Javascript" src="../js/FusionCharts.js"></script>
<link href="../css/960.css" rel="stylesheet" type="text/css" />
<link href="../css/reset.css" rel="stylesheet" type="text/css" />
<link href="../css/text.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/search.js"></script>

<script type="text/javascript" src="../js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="../js/slide.js"></script>
<script type="text/javascript" src="../js/loadgallery.js"></script>
<link href="../css/slideshow.css" rel="stylesheet" type="text/css" />
</head>

<body>

	<div class="grid_8 alpha">
		<div id="gallery">		
			<?php
				//get the values before the submit button
				$snfirst = $_POST['sn_first'];
				$snfirst2 = $_POST['sn_first2'];
				$snlast = $_POST['sn_last'];
				$snlast2 = $_POST['sn_last2'];
				$yearfirst = $_POST['year_first'];
				$yearfirst2 = $_POST['year_first2'];
				$yearlast = $_POST['year_last'];
				$yearlast2 = $_POST['year_last2'];
				$semester = $_POST['semester'];
				$semester2 = $_POST['semester2'];
				$kindofgraph = $_POST['kindofgraph'];
			
		
				
				$snnumber = $snfirst.$snlast;
				$snnumber2 = $snfirst2.$snlast2;
				$studentnumber = $snfirst."-".$snlast;
				$studentnumber2 = $snfirst2."-".$snlast2;
				$academicyear = $yearfirst.$yearlast;
				$academicyear2 = $yearfirst2.$yearlast2;
				$ayear = $yearfirst."-".$yearlast;
				
				
				// Connect to the DB
				$link = connectToDB();

				//$strXML will be used to store the entire XML document generated
				//Generate the graph element
				//fetch the name of the specified student number
				$strQuery0 = "select * from student where studentNumber='$snnumber'";
				$result0 = mysql_query($strQuery0) or die(mysql_error());
				$ors = mysql_fetch_array($result0);
				$fullname = $ors['firstName']." ".$ors['lastName'];
				
				$strQuery0 = "select * from student where studentNumber='$snnumber2'";
				$result0 = mysql_query($strQuery0) or die(mysql_error());
				$ors = mysql_fetch_array($result0);
				$fullname2 = $ors['firstName']." ".$ors['lastName'];
				
				if($semester == 1){
					$semname ="First";
				}
				else if($semester == 2){
					$semname = "Second";
				}
				else if($semester == 3){
					$semname = "Third";
				}
				$schoolyear = $semname." Semester ".$ayear;
							
				if($semester2 == 1){
					$semname2 ="First";
				}
				else if($semester2 == 2){
					$semname2 = "Second";
				}
				else if($semester2 == 3){
					$semname2 = "Third";
				}

				
				//if the selected graphs is for single semester
				if(($kindofgraph=='FCF_COLUMN2D') || ($kindofgraph=='FCF_BAR2D') || ($kindofgraph=='FCF_LINE')){
					$strXML = "<graph caption='$fullname' subCaption='$schoolyear' showBorder='1' showNames='1' formatNumberScale='0' decimalPrecision='2' yaxisminvalue='0' yaxismaxvalue='9' numdivlines='35'> ";
								
					$strQuerytotal = "select SUM(units) as totalunits from subjects where studentNumber='$snnumber' and academicYear='$yearfirst' and semester='$semester'";
					$resulttotal = mysql_query($strQuerytotal) or die(mysql_error());
					$orstotal = mysql_fetch_array($resulttotal);
							
							
					if($orstotal['totalunits']>0){
						$strQuery = "select * from subjects where studentNumber='$snnumber' and academicYear='$yearfirst' and semester='$semester'";
						$result = mysql_query($strQuery) or die(mysql_error());
						$total = 0;
							//Iterate through each factory
							if ($result) {
								while($ors = mysql_fetch_array($result)) {
									$total = $total + ($ors['grade'] * $ors['units']);
									//echo $total;
									//$strXML .= "<set name='" . $ors['grade'] . "' value='" . $percentage . "' />";
								}
							}
							$gwa = $total/$orstotal['totalunits'];
							//echo $gwa;
							$strXML .= "<set name='" . $fullname. "' value='" . $gwa . "' />";
						}
						
					$strQuerytotal = "select SUM(units) as totalunits from subjects where studentNumber='$snnumber2' and academicYear='$yearfirst' and semester='$semester'";
					$resulttotal = mysql_query($strQuerytotal) or die(mysql_error());
					$orstotal = mysql_fetch_array($resulttotal);
							
							
					if($orstotal['totalunits']>0){
						$strQuery = "select * from subjects where studentNumber='$snnumber2' and academicYear='$yearfirst' and semester='$semester'";
						$result = mysql_query($strQuery) or die(mysql_error());
						$total = 0;
							//Iterate through each factory
							if ($result) {
								while($ors = mysql_fetch_array($result)) {
									$total = $total + ($ors['grade'] * $ors['units']);
									//echo $total;
									//$strXML .= "<set name='" . $ors['grade'] . "' value='" . $percentage . "' />";
								}
							}
							$gwa = $total/$orstotal['totalunits'];
							//echo $gwa;
							$strXML .= "<set name='" . $fullname2. "' value='" . $gwa . "' />";
						}
						
						
					//close the link
					mysql_close($link);
					//Finally, close <graph> element
					$strXML .= "</graph>";
					$graph = $kindofgraph.".swf";
					//Create the chart - Pie 3D Chart with data from $strXML
					echo renderChart("../FusionCharts/$graph", "", $strXML, "FactorySum", 980, 450);
				}
				else if(($kindofgraph=='FCF_PIE3D') || ($kindofgraph=='FCF_DOUGHNUT2D') || ($kindofgraph=='FCF_FUNNEL') ){
					$strXML = "<graph caption='' subCaption='$schoolyear' pieSliceDepth='30' showBorder='1' showNames='1' numberSuffix='%'  formatNumberScale='0' decimalPrecision='2'> ";
								
					$strQuerytotal = "select SUM(units) as totalunits from subjects where studentNumber='$snnumber' and academicYear='$yearfirst' and semester='$semester'";
					$resulttotal = mysql_query($strQuerytotal) or die(mysql_error());
					$orstotal = mysql_fetch_array($resulttotal);
							
							
					if($orstotal['totalunits']>0){
						$strQuery = "select * from subjects where studentNumber='$snnumber' and academicYear='$yearfirst' and semester='$semester'";
						$result = mysql_query($strQuery) or die(mysql_error());
						$total = 0;
							//Iterate through each factory
							if ($result) {
								while($ors = mysql_fetch_array($result)) {
									$total = $total + ($ors['grade'] * $ors['units']);
									//echo $total;
									//$strXML .= "<set name='" . $ors['grade'] . "' value='" . $percentage . "' />";
								}
							}
							$gwa = $total/$orstotal['totalunits'];
							//echo $gwa;
							//$strXML .= "<set name='" . $semname." Semester ".$academicyear. "' value='" . $gwa . "' />";
						}
						
					$strQuerytotal = "select SUM(units) as totalunits from subjects where studentNumber='$snnumber2' and academicYear='$yearfirst' and semester='$semester'";
					$resulttotal = mysql_query($strQuerytotal) or die(mysql_error());
					$orstotal = mysql_fetch_array($resulttotal);
							
							
					if($orstotal['totalunits']>0){
						$strQuery = "select * from subjects where studentNumber='$snnumber2' and academicYear='$yearfirst' and semester='$semester'";
						$result = mysql_query($strQuery) or die(mysql_error());
						$total = 0;
							//Iterate through each factory
							if ($result) {
								while($ors = mysql_fetch_array($result)) {
									$total = $total + ($ors['grade'] * $ors['units']);
									//echo $total;
									//$strXML .= "<set name='" . $ors['grade'] . "' value='" . $percentage . "' />";
								}
							}
							$gwa2 = $total/$orstotal['totalunits'];
							//echo $gwa;
							//$strXML .= "<set name='" . $semname." Semester ".$academicyear. "' value='" . $gwa . "' />";
						}
				
					$ave = $gwa/($gwa+$gwa2)*100;
					$ave2 = $gwa2/($gwa+$gwa2)*100;
					
					$strXML .= "<set name='" . $fullname. "' value='" . $ave . "' />";
					$strXML .= "<set name='" . $fullname2. "' value='" . $ave2 . "' />";
					
					//close the link
					mysql_close($link);

					//Finally, close <graph> element
					$strXML .= "</graph>";
					$graph = $kindofgraph.".swf";
					//Create the chart - Pie 3D Chart with data from $strXML
					echo renderChart("../FusionCharts/$graph", "", $strXML, "FactorySum", 980, 450);
				
				}
				

				
				
			?>
		</div>	
	</div>


</body>
</html>
